# -*- coding: utf-8 -*-
"""
Routes of main webapp. Since we'll utilize HTML5 history api,
the route is only one for catching all route possibility.
"""

from webapp2 import Route
from webapp2_extras.routes import PathPrefixRoute
from application.api import handlers


# secure_scheme = 'https'

_routes = [
    PathPrefixRoute(r'/_', [
        # Users Resource
        Route(r'/users/me', handler=handlers.UserCheckApiHandler),
        Route(r'/users/register', handler=handlers.UserRegisterHandler),
        Route(r'/users/signin', handler=handlers.UserSigninHandler),
        Route(r'/users/signout', handler=handlers.UserSignoutHandler),

        # Items Resource
        Route(r'/items/list', name='items-list', handler=handlers.ItemQueryAllHandler),
        Route(r'/items/newest', name='items-newest', handler=handlers.ItemQueryLatest),
        Route(r'/items/popular', name='items-popular', handler=handlers.ItemQueryPopular),
        Route(r'/items/new', name='items-post-new', handler=handlers.ItemPostNew),
        Route(r'/items/search', handler=handlers.ItemSearchHandler),

        # Upload File Handlers
        Route(r'/upload-url', name='upload-url', handler=handlers.UploadURLHandler),
        Route(r'/upload-iprofile', handler=handlers.UploadImageProfileHandler),
        Route('/upload-iprofile-callback/<:([^/]+)?>', handler=handlers.UploadImageProfileCallback),
        Route(r'/upload-iitem', handler=handlers.UploadImageItemHandler),
        Route('/upload-iitem-callback/<:([^/]+)?>', handler=handlers.UploadImageItemCallback),
        Route('/upload-iitem-delete/<:([^/]+)?>', handler=handlers.UploadImageItemDeleteHandler),

        Route(r'/ping', handler=handlers.PingHandler),

        # Messaging Handlers
        Route('/message/new', handler=handlers.MessageNewHandler),
        Route('/message/list', handler=handlers.MessageListHandler),
        Route('/message/read', handler=handlers.MessageReadHandler),

        # Admin stuff resources
        Route(r'/admin/users/list', name='users-list', handler=handlers.UserQueryHandler),
        Route(r'/admin/items/list', name='admin-items-list', handler=handlers.ItemQueryHandler),
    ])
]


def get_routes():
    return _routes


def add_routes(app):
    # if app.debug:
    #     secure_scheme = 'http'
    for r in _routes:
        app.router.add(r)
